<template>
  <div>
    <div class="header">
      <van-button type="primary" @click="toProduct">主要按钮</van-button>
      <div class="mall">
        <span>新蜂商城|&nbsp;</span>
        <router-link
          tag="span"
          class="search-title"
          to="./product-list?from=home"
          >山河无恙，人间皆安</router-link
        >
      </div>
      <van-icon name="user-o" />
    </div>
    <swiper :list="swiperList"> </swiper>
    <nav-bar></nav-bar>
    <div>
      <!-- <div class="">新品上线</div> -->
      <img src="" alt="" />
    </div>
  </div>
</template>
<script>
import navBar from "@/components/NavBar";
import swiper from "@/components/Swiper";
import {getLocal }from "@/common/js/utils"
import { getHome } from "@/service/home.js";
import { Toast } from 'vant'
export default {
  components: {
    swiper,
    navBar,
  },
  data() {
    return {
      swiperList:[],
      newGoodses:[],
      hots:[],
      recommends:[],
    };
  },
  methods: {
    toProduct() {},
  },
  // mounted(){
  //    async recHome(){
  //     const result=await getHome()
  //    }
  // },
  //
//为什么这种写法就是不行的

  async mounted() {
    const token = getLocal('token')
    if (token) {
      this.isLogin = true
    }
    window.addEventListener('scroll', this.pageScroll)
    Toast.loading({
      message: '加载中...',
      forbidClick: true
    });
    const { data } = await getHome()
    this.swiperList = data.carousels
  
    this.newGoodses = data.newGoodses
    this.hots = data.hotGoodses
    this.recommends = data.recommendGoodses
    Toast.clear()
  },
}
</script>
<style lang="scss">
.header {
  display: flex;
  margin-top: -0.9375rem;
}
.mall {
  margin-left: 0.625rem;
  border: 0.0625rem solid gold;
}
</style>
